package com.lizardmind.haofudoctor.ui.studio.visit

import android.os.Bundle
import android.view.View
import com.linxiao.framework.activity.BaseActivity
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.manager.postApi
import com.lizardmind.haofudoctor.other.DoctorInfo
import com.lizardmind.haofudoctor.other.Request
import com.lizardmind.haofudoctor.other.SerializableBean
import com.lizardmind.haofudoctor.other.VisitBean
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_studio_visit.*
import kotlinx.android.synthetic.main.include_title_text.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.startActivity

/**
 *
 * Created by Extends on 2017/11/24 17:28
 */
class VisitStudioActivity:BaseActivity() {
    private val send = arrayListOf<VisitBean>()
    private val receive = arrayListOf<VisitBean>()
    private val good = arrayListOf<VisitBean>()
    private val manyi = arrayListOf<VisitBean>()
    override fun onCreatRootView(): View? {
        setContentView(R.layout.activity_studio_visit)
        return null
    }

    override fun onInitView(savedInstanceState: Bundle?) {

        //初始化title
        imgLeft.setImageResource(R.mipmap.back)
        imgLeft.onClick { finish() }
        titleText.text = "随访复诊"

        observe {
            postApi<Request<List<VisitBean>>>(hashMapOf(
                    "action" to "visit_manage",
                    "token" to DoctorInfo.token
            ), Consumer {
                it.dispose {
                    send.addAll(it)
                    receive.addAll(it.filter { it.documents_status==1 })
                    good.addAll(receive.filter { it.body_feel=="明显好转"})
                    manyi.addAll(receive.filter { it.evaluation_status==1&&it.evaluation.simple_experience<2 })

                    asv_send.text = send.count().toString()
                    asv_receive.text = receive.count().toString()
                    asv_good.text = good.count().toString()
                    asv_manyi.text = manyi.count().toString()

                    asv_cl0.onClick { startActivity<HistoryVisitActivity>("ser" to SerializableBean(send)) }
                    asv_cl1.onClick { startActivity<HistoryVisitActivity>("ser" to SerializableBean(receive)) }
                    asv_cl2.onClick { startActivity<HistoryVisitActivity>("ser" to SerializableBean(good)) }
                    asv_cl3.onClick { startActivity<HistoryVisitActivity>("ser" to SerializableBean(manyi)) }
                }
            })
        }
    }
}